﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using SolidWorksDll;
//using SolidWorks.Interop.sldworks;

namespace SWTest
{
    public partial class Form1 : Form
    {
        //private object string1;

        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(SolidWorksHelp.GetSwAppPath());
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            SolidWorksHelp.Test();
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            bool b=SolidWorksHelp.GetSwApp();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
                MessageBox.Show("获取失败");
        }

        private void Button5_Click(object sender, EventArgs e)
        {

            MessageBox.Show(SolidWorksHelp.GetSwAppPath());
        }

        private void Button6_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
                MessageBox.Show("获取失败"); ;
        }

        private void Button7_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp();
            if (false==b)
            {
                MessageBox.Show("获取成功");
                return;
            }
            MessageBox.Show(Test.GetVer());
        }

        private void Button8_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取失败");
                return;
            }
            Test.MakeWindowsSate(1);
            Thread.Sleep(2*1000);
            Test.MakeWindowsSate(2);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp();
           

            if (false == b)
            {
                MessageBox.Show("获取失败");
                return;
            }
            
            Test.MakeWindowsSate(1);
            Thread.Sleep(2 * 1000);
            Test.MakeWindowsSate(2);

            MessageBox.Show(Test.GetPath() + "-" + Test.GetVer());

        }

        private void button9_Click(object sender, EventArgs e)
        {
            
            var fdo =new OpenFileDialog();
            // FileDialog(msoFileDialogFilePicker)

            //打开单个文件
            fdo.Multiselect = false;
            fdo.Filter = "SolidWorks Part|*.SLDPRT|SolidWorks ASM|*.SLDASM|SolidWorks DRW|*.SLDDRW|All|*.*";//设定档案类型
            if (fdo.ShowDialog() == DialogResult.OK)
            {
                string str = fdo.FileName;
                bool b = SolidWorksHelp.OpenSwApp();
                ModelDocHelp.OpenDoc(str);
            }
            


            //打开多个文件
            //fdo.Multiselect = true;
            //fdo.Filter = "SolidWorks Part|*.SLDPRT|SolidWorks ASM|*.SLDASM|SolidWorks DRW|*.SLDDRW|All|*.*";//设定档案类型
            //if (fdo.ShowDialog() == DialogResult.OK) 
            //{
            //    string[] str = fdo.FileNames; 
            //}
            //else
            //{ 

            //}
            //foreach (string item in str)
            //{
            //    bool b = SolidWorksHelp.OpenSwApp();
            //}



            //    .Filters.Clear
            //    .Filters.Add "工程图", "*.drw;*.slddrw"
            //    .Filters.Add "All FIles", "*.*"
            //    .Show
            //    For i = 1 To.SelectedItems.Count
            //        ListBoxSelFiles.AddItem(.SelectedItems(i))
            //    Next
            //End With
        }

        private void button10_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            List < string> t = ModelDocHelp.GetAllDoc();
            foreach (var t1 in t)
            {
                textBox1.AppendText(Environment.NewLine + t1);
            }

        }

        private void button11_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp();
            string temPath =@"C:\ProgramData\SolidWorks\SolidWorks 2022\templates\gb_part.prtdot";
            string result = ModelDocHelp.NewDocumnet(temPath);
            if (result == "")
            {
                MessageBox.Show("创建零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Form frm = new 属性读取与同步();
            frm.ShowDialog();
        }
    }

}
